//
//  HWTabBarController.swift
//  HWPromoteProjectAPP
//
//  Created by 王昌健 on 2022/1/26.
//  Copyright © 2022 王昌健. All rights reserved.
//

import UIKit

class HWTabBarController1: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.//tabbar背景色
        UITabBar.appearance().backgroundColor = UIColor.white
        //tabbar字体颜色
        //        UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.colorWithHexString(hexString: "#5879FF"), NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 12)], for: .selected)
        //        // 修改标签栏未选中时文字颜色、字体
        //        UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.colorWithHexString(hexString: "#333333"), NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 12)], for: .normal)
        
        
        //        if #available(iOS 15.0, *)  {
        //            let appearance = UITabBarAppearance()
        //            appearance.configureWithOpaqueBackground()
        //            appearance.backgroundImage = UIColor.createImageWithColor(color: .white)
        //            appearance.shadowImage = UIColor.createImageWithColor(color: .white)
        //            UITabBar.appearance().standardAppearance = appearance
        //            UITabBar.appearance().scrollEdgeAppearance = appearance
        //
        //            UITabBar.appearance().tintColor = UIColor.colorWithHexString(hexString: "#5879FF")
        //            UITabBar.appearance().unselectedItemTintColor = UIColor.colorWithHexString(hexString: "#333333")
        //            UITabBar.appearance().layer.shadowColor = UIColor.colorWithAlphaHexString(hexString: "#EBEBEB", alpha: 0.34).cgColor
        //            UITabBar.appearance().layer.shadowOffset = CGSize(width: 0, height: -3)
        //            UITabBar.appearance().layer.shadowOpacity = 1
        //            UITabBar.appearance().layer.shadowRadius = 4
        //
        //        }else {
        UITabBar.appearance().backgroundImage = UIImage()
        UITabBar.appearance().shadowImage = UIImage()
        UITabBar.appearance().tintColor = .colorWithHexString(hexString: "#5879FF")
        UITabBar.appearance().unselectedItemTintColor = .colorWithHexString(hexString: "#333333")
        UITabBar.appearance().isTranslucent = false
        UITabBar.appearance().backgroundImage = UIImage()
        tabBar.layer.shadowColor = UIColor.colorWithAlphaHexString(hexString: "#EBEBEB", alpha: 0.34).cgColor
        tabBar.layer.shadowOffset = CGSize(width: 0, height: -3)
        tabBar.layer.shadowOpacity = 1
        tabBar.layer.shadowRadius = 4
        tabBar.layer.shadowPath = UIBezierPath(rect: tabBar.bounds).cgPath
        //        }
        //
        let home = HWHomeController()
        addControllerView(titlleStr: "首页", imageName: "tabbar_Home_Normal", selectImage: "tabbar_Home_Select", controller: home)
        
        let assetsController = HWAssetsController()
        addControllerView(titlleStr: "资产", imageName: "tabbar_Assets_Normal", selectImage: "tabbar_Assets_Select", controller: assetsController)
        
        let promoteController = HWPromoteController()
        addControllerView(titlleStr: "推广", imageName: "tabbar_Promote_Normal", selectImage: "tabbar_Promote_Select", controller: promoteController)
        
        let mineController = HWMineController()
        addControllerView(titlleStr: "我的", imageName: "tabbar_Mine_Normal", selectImage: "tabbar_Mine_Select", controller: mineController)
    }
    
}

extension HWTabBarController1 {
    func addControllerView(titlleStr : String, imageName: String ,selectImage :String , controller :UIViewController)  {
        
        let normalImage =    UIImage(named: imageName)
        controller.tabBarItem.image =  normalImage?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal)
        let seletimage =    UIImage(named: selectImage)
        controller.tabBarItem.selectedImage =  seletimage?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal);
        controller.tabBarItem.title = titlleStr
        let   nav =  HWNavigationController(rootViewController: controller)
        addChild(nav);
        
    }
}
